package com.lxj.core.dao;

import java.util.LinkedHashMap;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.lxj.common.utils.Page;
import com.lxj.core.entity.SYSBaseEntity;


public interface IBaseDao {
	
	public void setSessionFactory(SessionFactory sessionFactory) ;
	
	public Session getSession();
	
	public void save(SYSBaseEntity bean);
	
	public void delete(SYSBaseEntity bean);
	
	public void delete(Long id, Class<? extends SYSBaseEntity> clazz);
	
	public void delete(String propertyName, Object value, Class<? extends SYSBaseEntity> clazz);
	
	public <T extends SYSBaseEntity> T findById(long id, Class<T> clazz);
	
	public <T extends SYSBaseEntity> List<T> findByExample(T t) ;
	
	public <T extends SYSBaseEntity> List<T> findByExample(T t, LinkedHashMap<String,String> orderInfos) ;
	
	public <T extends SYSBaseEntity> List<T> findByExample(T t, String orderByPropertyName, String orderByType) ;

	public <T extends SYSBaseEntity> List<T> findByProperty(String propertyName, Object value, Class<T> clazz) ;
	
	public <T extends SYSBaseEntity> List<T> findByProperty(String propertyName, Object value, Class<T> clazz, LinkedHashMap<String,String> orderInfos) ;
	
	public <T extends SYSBaseEntity> List<T> findByProperty(String propertyName, Object value, Class<T> clazz, String orderByPropertyName, String orderByType) ;

	public <T extends SYSBaseEntity> List<T> findAll(Class<T> clazz);
	
	/*
	 * orderInfos 是有序的，hql中的order by段也是按此次序生成
	 * key==propertyName
	 * value==asc||desc
	 */
	public <T extends SYSBaseEntity> List<T> findAll(Class<T> clazz, LinkedHashMap<String,String> orderInfos);
	
	public <T extends SYSBaseEntity> List<T> findAll(Class<T> clazz, String orderByPropertyName, String orderByType);

	public <T extends SYSBaseEntity> T merge(T bean) ;

	public void attachDirty(SYSBaseEntity bean);

	public void attachClean(SYSBaseEntity bean) ;
	
	public boolean isExist(long id, Class<? extends SYSBaseEntity> clazz) ;
	
	
	//以下是分页的方法
	public Page findBy(Query query, int pageNumber, int pageSize);
	public Page findBy(Criteria criteria, int pageNumber, int pageSize);
	public Page findPageBy(Criteria criteria, int pageNumber, int pageSize);
	
	public List<Object> findBySql(String sql);
}
